import * as Cesium from "cesium";
import * as Turf from "@turf/turf";
import PolyLineMaterialPropetry from "./material/PolyLineMaterialPropetry";
export default class RectFyLIight {
  constructor(viewer) {
    // 在广州塔的经纬度坐标上进行增减操作，让其形成一个矩形区域
    this.bbox = [113.1191, 23.009, 113.4191, 23.209];
    // 在这个区域生成随机点
    const points = Turf.randomPoint(300, { bbox: this.bbox });
    // 根据生成的随机点生成线
    const features = points.features;
    features.forEach((item) => {
      // 获取点的经纬度
      const point = item.geometry.coordinates;
      // 转换起点坐标
      const startPoint = Cesium.Cartesian3.fromDegrees(point[0], point[1], 0);
      // 根据点设置结束点位置
      const endPoint = Cesium.Cartesian3.fromDegrees(
        point[0],
        point[1],
        200 + Math.random() * 3000 // 最少两百 最大1200高度
      );
      // 创建线
      const flyLine = viewer.entities.add({
        polyline: {
          positions: [startPoint, endPoint],
          width: 2,
          material: new PolyLineMaterialPropetry(),
        },
      });
    });
  }
}
